package com.atguigu.tingshu.common.util;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * 获取当前用户信息帮助类
 */
public class AuthContextHolder {

    /**
     * ThreadLocal在当前线程中进行存取数据，避免线程间数据污染
     * 弊端：无法在父子线程中传递数据
     * 解决：采用阿里提供TransmittableThreadLocal做到父子线程
     */
    private static ThreadLocal<Long> userId = new TransmittableThreadLocal<Long>();

    public static void setUserId(Long _userId) {
        userId.set(_userId);
    }

    public static Long getUserId() {
        return userId.get();
    }

    public static void removeUserId() {
        userId.remove();
    }

}
